package com.dy.树.验证二叉搜索树;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode() {
    }
}

public class Solution2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        List<TreeNode> list = new ArrayList<>();
        String s = in.next();
        String s1[] = s.split(",");
        for (int i = 0; i < s1.length; i++) {
            if (!s1[i].equals("None")) {
                list.add(new TreeNode(Integer.parseInt(s1[i])));
            } else list.add(null);
        }
        TreeNode root = list.get(0);
        for (int i = 0; i <= list.size() / 2 - 1; i++) {
            TreeNode node = list.get(i);
            if (i * 2 + 1 < list.size()) {
                node.left = (list.get(i * 2 + 1));
            }
            if (i * 2 + 2 < list.size()) {
                node.right = (list.get(i * 2 + 2));
            }
        }

        System.out.println(isValid(root));

    }


    //先中序遍历并存入list，然后在list中比较前后两位
    public static boolean isValid(TreeNode root) {
        List<Integer> list = new ArrayList<Integer>();
        inorder(root, list);
        for (int i = 0; i < list.size() - 1; ++i) {
            if (list.get(i) >= list.get(i + 1)) return false;
        }
        return true;
    }

    public static void inorder(TreeNode node, List<Integer> list) {
        if (node == null) return;
        inorder(node.left, list);
        list.add(node.val);
        inorder(node.right, list);
    }


}
